﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SelectStudents
{
    
    class Program
    {
    
        class Student
        {
            public string FirstName;
            public string LastName;
            public int age;


            public Student()
            {
                FirstName = "";
                LastName = "";
                age = 0;
            }
            public Student(string FN, string LN,int age)
            {
                FirstName = FN;
                LastName = LN;
                this.age = age;
            }


        }

        static void Main(string[] args)
        {
            List<Student> dnevnik = new List<Student> { new Student("Tihomir", "Tonchev",20), 
                                        new Student("elena", "ganeva",21),
                                        new Student("Boris", "minev",36), 
                                        new Student("Viktor", "Mitev",15) };
            int[] array = { 1, 3, 7, 21, 42, 5, 105 };
            string s = "ali baba"; 

            OrderByName(dnevnik);
            IOrderedEnumerable<Student> sorted = SortByAge(dnevnik);//.ThenBy(x => x.LastName);
            PrintStudents(sorted);
            DivideBy7And3(array);
            DivBy7And3LINQ(array);      
            s.ToName();
        }

        private static void DivBy7And3LINQ(int[] array)
        {
            var cheo = array.Where(x => x % 21 == 0);
            foreach (var item in cheo)
            {
                Console.WriteLine(item);
            }
        }

        private static void DivideBy7And3(int[] array)
        {
            var humbers = from num in array
                          where num % 7 == 0 & num % 3 == 0
                          select num;
            foreach (var num in humbers)
            {
                Console.WriteLine(num);
            }
        }

        private static void PrintStudents(IOrderedEnumerable<Student> sorted)
        {
            foreach (var student in sorted)
            {
                Console.WriteLine(student.FirstName + " " + student.LastName);
            }
        }

        private static IOrderedEnumerable<Student> SortByAge(List<Student> dnevnik)
        {
            var byAge = from st in dnevnik 
                        where st.age <= 24 & st.age > 18
                        select st;
            var sorted = dnevnik.OrderBy(x => x.FirstName);
            return sorted;
        }

        private static void OrderByName(List<Student> dnevnik)
        {
            var result = from student in dnevnik
                         where student.FirstName.CompareTo(student.LastName) < 0
                         select student;
        }
    }
}
